﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Message : MonoBehaviour
{
    public string Text {
        set { gameObject.GetComponent<Text>().text = value; }
    }

    float m_Life=2;
    float m_CurLife = 0;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        m_CurLife += Time.deltaTime;
        if(m_CurLife > m_Life)
        {
            gameObject.SetActive(false);
            Destroy(gameObject);
            return;
        }
        Text text = gameObject.GetComponent<Text>();
        RectTransform rect = gameObject.GetComponent<RectTransform>();

        //  transparent
        float process = 1.0f - m_CurLife / m_Life;
        Vector4 newColor = text.color;
        newColor.w = process;
        text.color = newColor;

        //  position
        int screenHeight = (int)(Screen.height / UtilsUnity.GetCanvasScale());
        float newHeight = screenHeight / 4 + ((1 - process) * (screenHeight / 4));
        rect.localPosition = new Vector3(0, newHeight);


    }
}
